package com.ly.credit.controller;

import com.ly.credit.entity.User;
import com.ly.credit.service.ApiService;
import com.ly.credit.service.UserService;
import com.ly.credit.util.AdResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class AboutApiController {
	@Resource
	private HttpServletRequest request;
	@Resource
	private ApiService apiService;
	@Resource
	private UserService userService;
	@RequestMapping("/aboutApi.do")
	public String aboutApi(ModelMap map,
	                       @RequestParam(required = true, value = "apiId") Integer apiId ){
		HttpSession session = request.getSession();
		User user =(User) session.getAttribute("user");
		if(user==null){
			return "login";
		}
		AdResult adResult = apiService.getByApiId(apiId);
		AdResult apiList = apiService.getAll();
		map.put("apiList",apiList);
		map.put("api",adResult);
		map.put("user",user);
		return "views/aboutApi";
	}
	@RequestMapping("/getkey.do")
	@ResponseBody
	public AdResult getkey(ModelMap map){
		AdResult adResult = userService.getKey();
		return adResult;
	}
}
